package com.guiji.job.controller;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.guiji.common.annotation.RepeatSubmit;
import com.guiji.common.annotation.Log;
import com.guiji.common.core.controller.BaseController;
import com.guiji.common.core.domain.AjaxResult;
import com.guiji.common.enums.BusinessType;
import com.guiji.job.vo.JobChangeRecordVo;
import com.guiji.job.bo.JobChangeRecordQueryBo;
import com.guiji.job.bo.JobChangeRecordAddBo;
import com.guiji.job.bo.JobChangeRecordEditBo;
import com.guiji.job.service.IJobChangeRecordService;
import com.guiji.common.utils.poi.ExcelUtil;
import com.guiji.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 任务状态变更Controller
 *
 * @author 钟维澎（四月）
 * @date 2021-07-02
 */
@Api(value = "任务状态变更控制器", tags = {"任务状态变更管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/changeRecord/changeRecord")
public class JobChangeRecordController extends BaseController {

    private final IJobChangeRecordService iJobChangeRecordService;

    /**
     * 查询任务状态变更列表
     */
    @ApiOperation("查询任务状态变更列表")
    @PreAuthorize("@ss.hasPermi('changeRecord:changeRecord:list')")
    @GetMapping("/list")
    public TableDataInfo<JobChangeRecordVo> list(@Validated JobChangeRecordQueryBo bo) {
        return iJobChangeRecordService.queryPageList(bo);
    }

    /**
     * 导出任务状态变更列表
     */
    @ApiOperation("导出任务状态变更列表")
    @PreAuthorize("@ss.hasPermi('changeRecord:changeRecord:export')")
    @Log(title = "任务状态变更", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<JobChangeRecordVo> export(@Validated JobChangeRecordQueryBo bo) {
        List<JobChangeRecordVo> list = iJobChangeRecordService.queryList(bo);
        ExcelUtil<JobChangeRecordVo> util = new ExcelUtil<JobChangeRecordVo>(JobChangeRecordVo.class);
        return util.exportExcel(list, "任务状态变更");
    }

    /**
     * 获取任务状态变更详细信息
     */
    @ApiOperation("获取任务状态变更详细信息")
    @PreAuthorize("@ss.hasPermi('changeRecord:changeRecord:query')")
    @GetMapping("/{id}")
    public AjaxResult<JobChangeRecordVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iJobChangeRecordService.queryById(id));
    }

    /**
     * 新增任务状态变更
     */
    @ApiOperation("新增任务状态变更")
    @PreAuthorize("@ss.hasPermi('changeRecord:changeRecord:add')")
    @Log(title = "任务状态变更", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody JobChangeRecordAddBo bo) {
        return toAjax(iJobChangeRecordService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改任务状态变更
     */
    @ApiOperation("修改任务状态变更")
    @PreAuthorize("@ss.hasPermi('changeRecord:changeRecord:edit')")
    @Log(title = "任务状态变更", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody JobChangeRecordEditBo bo) {
        return toAjax(iJobChangeRecordService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除任务状态变更
     */
    @ApiOperation("删除任务状态变更")
    @PreAuthorize("@ss.hasPermi('changeRecord:changeRecord:remove')")
    @Log(title = "任务状态变更" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iJobChangeRecordService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
